package com.yeqian.attachment.utils;

import com.yeqian.system.exceptions.SystemAccountException;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.Set;

@Component
public class FileUploadUtil {


    public static void checkFileExt(String ext, Set<String> allowFileExt)  {
        Assert.hasLength(ext, "获取文件后缀失败");
        String error = String.format("禁止上传%s后缀文件", ext);
        if (allowFileExt.isEmpty()) {
            throw new SystemAccountException(error);
        } else {
            ext = ext.trim().toLowerCase();
            if (!allowFileExt.contains(ext)) {
                throw new SystemAccountException(error);
            }
        }
    }
}
